/*
 *所有关于tb_project_subjectexpensedetailinfo类的业务代码应在此处编写
*可使用repository.调用常用方法，获取EF/Dapper等信息
*如果需要事务请使用repository.DbContextBeginTransaction
*也可使用DBServerProvider.手动获取数据库相关信息
*用户信息、权限、角色等使用UserContext.Current操作
*tb_project_subjectexpensedetailinfoService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
*/
using MYData.Core.BaseProvider;
using MYData.Core.Extensions.AutofacManager;
using MYData.Entity.DomainModels;
using System.Linq;
using MYData.Core.Utilities;
using System.Linq.Expressions;
using MYData.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using MYData.System.IRepositories;
using MYData.Core.EFDbContext;
using MYData.Entity.DTO.ApiEntity.Input;
using Mapster;

namespace MYData.System.Services
{
    public partial class tb_project_subjectexpensedetailinfoService
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly Itb_project_subjectexpensedetailinfoRepository _repository;//访问数据库
        private readonly VOLContext _context;

        [ActivatorUtilitiesConstructor]
        public tb_project_subjectexpensedetailinfoService(
            Itb_project_subjectexpensedetailinfoRepository dbRepository,
            IHttpContextAccessor httpContextAccessor
,
            VOLContext context)
        : base(dbRepository)
        {
            _httpContextAccessor = httpContextAccessor;
            _repository = dbRepository;
            _context = context;
            //多租户会用到这init代码，其他情况可以不用
            //base.Init(dbRepository);
        }

        WebResponseContent webResponse = new WebResponseContent();

        /// <summary>
        /// 添加科目报销信息
        /// </summary>
        /// <returns></returns>
        public WebResponseContent InsertSubjectExpenseInfo(SubjectExpenseInput_Dto inputDto)
        {
            var model = inputDto.Adapt<tb_project_subjectexpensedetailinfo>();
            _repository.Add(model);
            return webResponse.OK("添加成功", _repository.SaveChanges());
        }

        /// <summary>
        /// 修改科目报销信息
        /// </summary>
        /// <returns></returns>
        public WebResponseContent UpdateSubjectExpenseInfo(SubjectExpenseUpdate_Dto inputDto)
        {
            var model = inputDto.Adapt<tb_project_subjectexpensedetailinfo>();
            _repository.Update(model);
            return webResponse.OK("修改成功", _repository.SaveChanges());
        }

        /// <summary>
        /// 根据科目ID获取实体信息
        /// </summary>
        /// <param name="SubjectId"></param>
        /// <returns></returns>
        public WebResponseContent GetSubjectExpenseInfo(string SubjectId)
        {
            var list = _repository.Find(x => x.subjectId.Equals(SubjectId)).FirstOrDefault();
            return webResponse.OK("实体信息获取成功", list);
        }

        /// <summary>
        /// 根据科目ID 查询是否为可判断条件
        /// </summary>
        /// <param name ="subjectId">科目Id</param>
        /// < returns ></ returns >
        public WebResponseContent GetIsJudge(string subjectId)
        {
            var jsonValue = _repository.Find(x => x.subjectId.Equals(subjectId)).FirstOrDefault().jsonValue;
            dynamic model = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(jsonValue);
            return webResponse.OK("", model);
        }
    }
}
